package com.baoer.service.impl;

import com.baoer.R;
import com.baoer.entity.User;
import com.baoer.mapper.LoginMapper;
import com.baoer.service.LoginService;
import com.baoer.util.JwtUtil;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Chen Feiya
 * @CreateTime: 2025-07-01
 * @Description:
 * @Version: 1.0
 */



@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private JwtUtil jwtUtil;

    @Override
    public Map<String,Object> login(Integer userid, String password) {
        // 1. 查询用户
        User user = loginMapper.findByUserid(userid, password);

        if(user != null) {
            Map<String, Object> map = new HashMap<>();
            map.put("user", user);
            String token = jwtUtil.putToken(map);
            map.put("token", token);
            System.out.println(token);
            System.out.println("map:" + map);
            return map;
        }
        return R.er("用户名或密码不正确");
    }
}